package com.ziyucoding.springboot.labs.lab8.skywalking.redisdemo.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * @author ziyucoding
 * @date 2022-10-31
 **/
@RestController
@RequestMapping("/demo")
public class DemoController {

    @Autowired
    private StringRedisTemplate redisTemplate;

    @GetMapping("/redis")
    public Map<String, Object> redis() {
        String initPassword = String.valueOf(this.get("sys_config:sys.user.initPassword"));
        Map<String, Object> result = new HashMap<>();
        result.put("code", 0);
        result.put("msg", "成功");
        result.put("data", initPassword);
        return result;
    }

    private Object get(String key) {
        return redisTemplate.opsForValue().get(key);
    }

}
